home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************
-
- Some demo code
-
- --Eric Johnson 5/25/92 (Modified by isl 6/5/92)
-
- This is hack -- it was written to simply test the classes.
- At the very least, an appropriate exception catcher should be setup.
- Everything would also work much better from inside a real application.
-
- **************************************************************************/
-
- #include "CTCPClient.h"
-
- extern tSystem gSystem; // System information
-
- void main()
- Begin
- CTCPClient* MyNetwork;
- TCPiopb* asyncResult;
- TCPStatusPB MyStatus;
- TCPParam MyParam;
- TCPStats MyStats;
- char name[kNameLength];
- ip_addr address;
- ip_port port;
- char* input= Null;
- Size inputLength= 200;
- char output[200];
- OSErr error= noErr;
- short errorCount= Null;
- Boolean quit= False;
- Boolean close= False;
-
- TRY
- {
- gSystem.systemVersion= 0x0603;
- FailOSErr(error);
- errorCount++;
-
- MyNetwork= new CTCPClient;
- MyNetwork->ITCPClient();
-
- printf("We are contacting a server...\n");
-
- strcpy(name, "mars"); // Any machine name with an FTP daemon running will do here....
- printf("Resolving %s...\n\n", name);
- MyNetwork->SetAddress(name, address= Null, port= 21);
- MyNetwork->GetStream()->GetDestination(name, &address, &port);
- printf("Name: %s;\nAddress: 0x%lx or %lu;\nPort: %d.\n\n", name, address, address, port);
-
- FailOSErr(error= MyNetwork->Create(8192) );
- errorCount++;
- quit= True;
- printf("I've just created a stream...\n");
-
- FailOSErr(error= MyNetwork->OpenConnection() );
- errorCount++;
- close= True;
- printf("I've just opened a connection...\n");
- MyNetwork->SetRetries(5);
- FailOSErr(error= MyNetwork->ReceiveData(&input, &inputLength) );
- errorCount++;
- printf("We received %lu bytes of data back.\n", inputLength);
- if (inputLength >= 200)
- input[199]= 0;
- printf("Data: %s\n", input);
- printf("\n=+=+=+=+=+=+=+=+=+=+=\n\n");
-
- FailOSErr(error= MyNetwork->GetStream()->Status(&MyStatus) );
- errorCount++;
- printf("Status: \n");
- printf(" Last round trip time was %lu ms.\n",MyStatus.lastRTT);
- printf(" Smoothed round trip time was %lu ms.\n",MyStatus.srtt);
- printf("\n\n\nPress <Return> to continue.\n\n"); getchar();
- printf("\n=+=+=+=+=+=+=+=+=+=+=\n\n");
-
- strcpy(output, "Hi \n");
- printf("Sending data (Hi )...\n");
- FailOSErr(error= MyNetwork->SendData(output, strlen(output)) );
- errorCount++;
-
- MyNetwork->SetRetries(5);
- FailOSErr(error= MyNetwork->MyBufferReceiveData(input, &inputLength) );
- errorCount++;
- printf("We received %lu bytes of data back.\n", inputLength);
- if (inputLength >= 200)
- input[199]= Null;
- else
- input[inputLength]= Null;
- printf("Data: %s\n", input);
- ForgetPtr(input);
-
- printf("The last error was %d.\n", error= MyNetwork->GetStream()->GetLastError());
- printf("\n=+=+=+=+=+=+=+=+=+=+=\n\n");
-
- FailOSErr(error= MyNetwork->GetStream()->Status(&MyStatus) );
- errorCount++;
- printf("Status: \n");
- printf(" Last round trip time was %lu ms.\n",MyStatus.lastRTT);
- printf(" Smoothed round trip time was %lu ms.\n",MyStatus.srtt);
- printf("\n=+=+=+=+=+=+=+=+=+=+=\n\n");
-
- printf("Okay... now for some of the technical data...\n");
- FailOSErr(error= MyNetwork->GetStream()->GlobalInfo(&MyParam, &MyStats) );
- errorCount++;
- printf(" tcpMaxWindow: %lu \n",MyParam.tcpMaxWindow);
- printf(" tcpMaxConn: %lu \n",MyParam.tcpMaxConn);
- printf(" tcpMaxSegSize: %lu \n",MyParam.tcpMaxSegSize);
- printf(" tcpOctetsRetrans: %lu \n",MyStats.tcpOctetsRetrans);
- printf(" tcpRetransPkts: %lu \n",MyStats.tcpRetransPkts);
- printf(" tcpOctetsIn: %lu \n",MyStats.tcpOctetsIn);
- printf("\n=+=+=+=+=+=+=+=+=+=+=\n\n");
-
- MyNetwork->SetRetries(5);
- FailOSErr(error= MyNetwork->GetLocalAddress(&address) );
- errorCount++;
- printf("And my address is 0x%lx or %lu.\n\n", address, address);
-
- FailOSErr(error= MyNetwork->Close() );
- errorCount++;
- printf("I've just closed our connection.\n");
-
- FailOSErr(error= MyNetwork->Quit() );
- errorCount++;
- printf("I've just released our stream.\n");
-
- printf("The last error was %d.\n", error= MyNetwork->GetStream()->GetLastError());
- printf("\n=+=+=+=+=+=+=+=+=+=+=\n\n");
-
- ForgetObject(MyNetwork);
- }
- CATCH
- {
- SysBeep(5);
- Debugger();
- if (close) error= MyNetwork->Close();
- if (quit) error= MyNetwork->Quit();
- error= MyNetwork->Kill();
- NO_PROPAGATE;
- }
- ENDTRY
- }
-